﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using TestForeignVocabulary.Properties;


public enum ModeTrad {FR2EN, EN2FR}

namespace TestForeignVocabulary
{
    public class FicheInfo
	{
	#region Constant

		public static readonly  string APPLICATION_NAME = "Test Foreign Vocabulary";
		public static readonly	string APPLICATION_VERSION;

	#endregion
	#region Attributs & Properties

		private int _nNbTranslation;
		public int NbTranslation
		{
			get 
			{
				int nNbTranslationMax = ExerciceTrad.NbTranslationDico;
				if( ExerciceTrad.NbTranslationImport > 0 )
					nNbTranslationMax = ExerciceTrad.NbTranslationImport;

				if (_nNbTranslation <= 0 || _nNbTranslation > nNbTranslationMax)
				{
					return nNbTranslationMax;
				}				

				return _nNbTranslation; 
			}
			set
			{ 	
				/*			
				if( value <= 0 )
				{
					_nNbTranslation = ExerciceTrad.NbTranslationExercice;
				}
				else	
				 * */
				{
					_nNbTranslation = value;
				}
			}
		}

		private int _nNbAttemptInProgress;
		public int NbAttemptInProgress
		{
			get { return _nNbAttemptInProgress; }
			private set { _nNbAttemptInProgress = value; }
		}

		private TranslationExercise _oExerciceTrad;
		public TranslationExercise ExerciceTrad
		{
			get { return _oExerciceTrad; }
			private set { _oExerciceTrad = value; }
		}
				
        public bool HasOptionLaisserAfficherMotTraduit
        {
            get
            {
                return (bool)Settings.Default["bOptionLaisserAfficherMotTraduit"];
            }

            set
            {
                Settings.Default["bOptionLaisserAfficherMotTraduit"] = value;
                Settings.Default.Save();
            }
        }

        public string OptionEnglishDirectoryPath
        {
            get
            {
                string strEnglishDirectoryPath = (string)Settings.Default["strEnglishDirectoryPath"];
                if( strEnglishDirectoryPath == "" )
					return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

				return strEnglishDirectoryPath;
            }

            set
            {
                Settings.Default["strEnglishDirectoryPath"] = value;
                Settings.Default.Save();
            }
        }

		public int OptionEnglishFilterIndexExtension
		{
			get
			{			
				return (int)Settings.Default["nEnglishFilterIndexExtension"];
			}

			set
			{
				Settings.Default["nEnglishFilterIndexExtension"] = value;
				Settings.Default.Save();
			}
		}

    #endregion
    #region Constructors

		static FicheInfo()
		{
			APPLICATION_VERSION = string.Format("v {0}.{1}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major.ToString(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString());
		}

        public FicheInfo()
        {
			ExerciceTrad = new TranslationExercise();
			ExerciceTrad.LoadBinary();
        }
    
    #endregion
    #region Methods - Operation

        public void InitExercise()
        {
			NbAttemptInProgress = 1;
			ExerciceTrad.MixList(true, NbTranslation);
			ExerciceTrad.InitTranslated();
        }

		public void VerifExercise()
		{
			
		}

        public void NextExercise()
        {            
            NbAttemptInProgress++;
			ExerciceTrad.MixList();
        }

	#endregion
	#region Methods - Data

        public void SaveDico()
        {
			ExerciceTrad.SaveBinary();
        }

        public bool LoadDico()
        {			
			if (ExerciceTrad.LoadBinary())
            {				
				NbTranslation = -1;
                return true;
            }
			
            return false;
        }

        public void ClearDico()
        {
			NbTranslation = 0;
			ExerciceTrad.ClearBinary();
        } 

        public void Import(string strFileName )
        {			
			ExerciceTrad.Import( strFileName );			
			NbTranslation = -1;
        }

		public void Export(string strFileName)
		{
			ExerciceTrad.Export(strFileName);			
		}
    #endregion
    }
}
